var baseUrl = require('commonUrl.js')
/**
 * get请求
 */
function getHttp(url, param, callback, fail) {
  var token = wx.getStorageSync("token")
  wx.showLoading({
    title: "加载中",
  })
  wx.request({
    url: baseUrl.baseUrl+ url,
    method: 'GET',
    data: param,
    header: {
      'authorization': "BasicAuth "+token
    },
    success(res) {
      wx.hideLoading()
      if (res.statusCode == 200) {
        if (res.data.Code != 9|| res.data.Code != 405) {
          callback(res.data)
        } else {
          console.log("登陆过期")
        }
      } else {
        fail()
      }
    },
    fail() {
      fail()
    }
  })
}

/**
 * post请求
 */
function PostHttp(url, param, callback, fail) {
  var token = wx.getStorageSync("token")
  wx.showLoading({
    title: "加载中",
  })
  wx.request({
    url: baseUrl.baseUrl + url,
    method: 'POST',
    data: param,
    header: {
      'authorization': "BasicAuth " + token
    },
    success(res) {
      wx.hideLoading()
      if (res.statusCode == 200) {
        if (res.data.Code != 9 || res.data.Code != 405) {
          callback(res.data)
        } else {
          console.log("登陆过期")
        }
      } else {
        fail()
      }
    },
    fail() {
      fail()
    }
  })
}
module.exports.getHttp = getHttp
module.exports.PostHttp = PostHttp